﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static CSharp.Study_DelegateEvent.EventDemo.Publisher;

namespace CSharp.Study_DelegateEvent.EventDemo
{
    /// <summary>
    /// 事件订阅者
    /// 事件方法编写和订阅事件
    /// </summary>
    internal class Subscriber
    {
        private string CustomName;

        //订阅的动作要写在这里面，所以要传过来发布者
        public Subscriber(string customName, Publisher publisher)
        {
            CustomName = customName;
            //事件订阅
            publisher.CustomEvent += HanderCustomEvent;
        }

        /// <summary>
        /// 订阅者定义事件 执行的方法
        /// </summary>
        private void HanderCustomEvent(object sender, CustomEventArgs e)
        {
            //在这里做要做的事
            Console.WriteLine($"发布者：{sender.GetType()}，订阅者：{CustomName}，参数：{e.OtherData}");
        }
    }
}
